package com.leyou.page.web;

import com.leyou.page.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@Controller
public class PageController {

    @Autowired
    private PageService pageService;


    @RequestMapping("/item/{id}.html")
    public String toItemHtml(Model model,@PathVariable("id") Long id){
        // 根据id查询内容
        Map<String,Object> map = pageService.loadItemData(id);
        // 存入model
        model.addAllAttributes(map);
        // 返回模板名称
        return "item";
    }



    /**  以前交给springmvc的视图解析器解析
     *   prefix:   /view/
     *   subfix:   .jsp
     *
     *   /view/hello.jsp   最后执行的页面
     *
     *   现在用的Thymeleaf  ： 模板解析器 加载【ThymeleafProperties】
     *   	public static final String DEFAULT_PREFIX = "classpath:/templates/";
     * 	    public static final String DEFAULT_SUFFIX = ".html";
     */
    /*@RequestMapping("/hello")
    public String hello(Model model){
        model.addAttribute("msg", "小猪猪真的好纯啊！");
        return "hello";
    }*/
}
